package 尚硅谷.juc.test1;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

public class VolatileDemo {

    public static void main(String[] args) {
        Test1 test1=new Test1();
        new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"开始执行");
            try {
                TimeUnit.SECONDS.sleep(3);
                test1.addNum();
                System.out.println(Thread.currentThread().getName()+"获取到num："+test1.num);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"AA").start();
        while (test1.num==0){
            //main线程一直在这里等待，直到num的值不等于0
        }
        System.out.println("主线程执行完毕..............");
    }
}
